//分页的参数
	//totalRecord：总共多少条记录数  ，totalPage: 分几页显示， pageSize: 每页显示多少记录数 ; curPage 当前页  order 排序字段
	function getPagePars(){
		var pagePars = "";
		//pagePars += "&totalRecord="+$("totalRecord").text();
		//pagePars += "&totalPage="+$("pagination span:last").text();
		/*pagePars += "&pageSize="+$("pagination select.pageSize").val();
		pagePars += "&curPage="+$("pagination span.choose").text();*/
		//order += "&order="+$("pagination span.order").text();
		pagePars = {
 	            'pageSize' : $("pagination select.pageSize").val(),
 	            'currentPage' : $("pagination span.choose").text()
 	        };
//		alert($("pagination select.pageSize").val() +"-"+$("pagination span.choose").text());
		return pagePars;	
	}
	//初始化分页查询
	function initPage(){
		var pagePars = {
 	            'pageSize' : $("pagination select.pageSize").val(),
 	            'currentPage' : "1"
 	        };
		//触发查询
		queryForPagination(pagePars);
	}
	
	//查询后返回初始化分页
	function initPageReturn(totalRecord){
		var totalPage = Math.ceil(totalRecord/$("pagination select.pageSize").val());
		$("totalRecord").text(totalRecord);
		
		//删除页码
		$("pagination span").detach();
		$("pagination dot").detach(); 
		
		if(totalPage < 6){   
			for(var i=totalPage ; i>0 ; i--){ 
				$("pre").after("<span>"+i+"</span>");	
			}
		}
		
		if(totalPage >= 6){
			$("pre").after("<span>"+totalPage+"</span>");
			$("pre").after("<dot>•••</dot>");	
			for(var i=3 ; i>0 ; i--){ 
				$("pre").after("<span>"+i+"</span>");	
			} 
		}
		$("pagination pre").addClass("disable");
		if(totalPage == 1 || totalPage == 0){
			$("pagination next").addClass("disable");
		}else{
			$("pagination next").removeClass("disable");
		}
		$("pagination span").eq(0).addClass("choose");
	}
	
	function initPageNum(totalPage){
		//删除页码
		$("pagination span").detach();
		$("pagination dot").detach(); 
		
		if(totalPage < 6){   
			for(var i=totalPage ; i>0 ; i--){ 
				$("pre").after("<span>"+i+"</span>");	
			}
		}
		
		if(totalPage >= 6){
			$("pre").after("<span>"+totalPage+"</span>");
			$("pre").after("<dot>•••</dot>");	
			for(var i=3 ; i>0 ; i--){ 
				$("pre").after("<span>"+i+"</span>");	
			} 
		}
		$("pagination pre").addClass("disable");
		if(totalPage == 1 || totalPage == 0){
			$("pagination next").addClass("disable");
		}else{
			$("pagination next").removeClass("disable");
		}
		$("pagination span").eq(0).addClass("choose");
		//触发查询
		queryForPagination(getPagePars());
	}
	
	
	//改变页数
	$(document).delegate("pagination span","click",function(event) {
		 
			//var totalRecord = Number($("totalRecord").text());
			//var pageSize = Number($("pagination select.pageSize").val()); 
			var totalPage = Number($("pagination span:last").text());  
			var curPage = $(this).text();
			var thisClass = $(this).attr("class");			
			if(thisClass == "choose"){return;}			
			 
			$("pagination pre").removeClass("disable");
			$("pagination next").removeClass("disable");
			$("pagination span").removeClass("choose");			
			
			$(this).addClass("choose"); 
			
			//倒数第二页
			if((Number(curPage) + 1) == totalPage ){  
				//触发查询
				queryForPagination(getPagePars());
				return;
			} 
			
			//倒数第一页
			if(Number(curPage) == totalPage ){ 
				$("pagination next").addClass("disable"); 
				//触发查询
				queryForPagination(getPagePars());
				return;	
//				if($(this).prev().html()!= "•••"){
//					return;	
//				} 
			}			
			 
			//首页
			if(curPage == 1){ 
				initPageNum(totalPage);
				$("pagination pre").addClass("disable");
				return;	 
			}   
			
			if(curPage > 1 && totalPage > 5){
				initChangeNum(curPage,totalPage);
				return;
			}   
			//触发查询
			queryForPagination(getPagePars());
		 
	});
	 
		
	//前一页	 		
	$(document).delegate("pre","click",function(e) {
		var thisClass = $(this).attr("class"); 
		if(thisClass == "disable") return; 
		$("next").removeClass("disable");
		var thisClass = $(this).attr("class");			
		if(thisClass == "disable") return;			 
		var totalPage = Number($("pagination span:last").text());  
		var curPage = $("pagination span.choose").text();
		
		if(totalPage < 6){  
			$("pagination span.choose").prev().addClass("choose");
			$("pagination span.choose:last").removeClass("choose");
			if(curPage == (Number(totalPage)-1)){ 
				$("pagination next").addClass("disable"); 
			}	
			if((Number(curPage) -1) == 1){ 
				$("pagination pre").addClass("disable"); 
			}
			//触发查询
			queryForPagination(getPagePars());
	    }else{ 
			if(curPage == 2){
				initPageNum(totalPage);
			}	
			if(curPage > 2 && totalPage > 5){ 
				initChangeNum(Number(curPage)-1,totalPage);
			} 
		}
	});
	 
	
	//下一页面
	$(document).delegate("next","click",function(e) {
        var thisClass = $(this).attr("class"); 
		if(thisClass == "disable") return; 
		$("pre").removeClass("disable");
		var totalPage = Number($("pagination span:last").text());  
		var curPage = $("pagination span.choose").text();
		
	    if(totalPage < 6){  
		    $("pagination span.choose").next().addClass("choose");
			$("pagination span.choose:first").removeClass("choose");
			if(curPage == (Number(totalPage)-1)){ 
				$("pagination next").addClass("disable"); 
			}	
			//触发查询
			queryForPagination(getPagePars());
	    }else{ 
			if(curPage == (Number(totalPage)-1)){
				$("pagination span.choose").removeClass("choose");
				$("pagination span:last").addClass("choose");
				$("pagination next").addClass("disable");
				return;
			}	
			initChangeNum(Number(curPage)+1,totalPage);
		} 
    });
	
	//分页size变化
	$(document).delegate("pagination select","change",function(e) {
		var totalPage = Math.ceil($("totalRecord").text()/$("pagination select.pageSize").val());
		initPageNum(totalPage);
    });
	
	//点击go
	$(document).delegate("go","click",function(e) {
		var totalPage = Number($("pagination span:last").text());  
		var curPage = $("pagination input").val();
		//验证输入的是否为数字
		var reg = new RegExp("^[0-9]*$");
		if(!reg.test(curPage)) {
			return;
		}
		//输出的值大于最大页
		if(Number(curPage)>=totalPage){
			if(totalPage<=5){
				if(totalPage != 1 && totalPage != 0)$("pagination pre").removeClass("disable");
				$("pagination span.choose").removeClass("choose");
				$("pagination span:last").addClass("choose");
				$("pagination next").addClass("disable");
				//触发查询
				queryForPagination(getPagePars());
			}else {
				initChangeNum(totalPage,totalPage);
			}
		} else if(Number(curPage)<=1){
			initPageNum(totalPage);
			$("pagination pre").addClass("disable");
		} else {
			initChangeNum(curPage,totalPage);
		}
		
    });
		
	 
 	function initChangeNum(curPage,totalPage){
		//删除页码
		$("pagination span").detach();
		$("pagination dot").detach(); 
		var pageHtml = "";
		
		$("pagination pre").removeClass("disable");
		$("pagination next").removeClass("disable");
				
		if(curPage == totalPage){
			$("pagination next").addClass("disable");
			pageHtml += "<span>1</span>";
			if((Number(totalPage)-2) > 1){
				pageHtml += "<dot>•••</dot>";
			}
			pageHtml += "<span>"+(Number(totalPage)-2)+"</span>";
			pageHtml += "<span>"+(Number(totalPage)-1)+"</span>";
			pageHtml += "<span class='choose'>"+totalPage+"</span>";
			 
		}else{  			
			if( (Number(curPage) - 1) != 1 ){
				pageHtml += "<span>1</span>";
			}				
			if((Number(curPage)-2) > 1){
				pageHtml += "<dot>•••</dot>";	
			}
			
			pageHtml += "<span>"+(Number(curPage)- 1)+"</span>";
			pageHtml += "<span class='choose'>"+curPage+"</span>";
			pageHtml += "<span>"+(Number(curPage)+ 1)+"</span>";
			if((Number(curPage)+1) < (Number(totalPage) - 1)){
				pageHtml += "<dot>•••</dot>";	
			}
			
			if( (Number(curPage)+ 1) != totalPage ){
				pageHtml += "<span>"+totalPage+"</span>";
			} 
		} 
		$("pre").after(pageHtml);	 
		//触发查询
		queryForPagination(getPagePars());
	}